﻿@model Topic
@{

    var _smiles = ViewBag.Smiles as List<Smile>;

    var _cmd = (CommandType)ViewBag.CommandType;

    bool _isMod = ViewBag.IsMod;

    var _isNewPost = _cmd == CommandType.NewPoll || _cmd == CommandType.NewPost;

}
<div class="widget white-t">
    <div class="header">
        <span class="icon"></span>
        <h1>
            @ViewBag.ActiveUrl.Title
        </h1>
    </div>
    

    @using (Html.Kaio().BeginForm(ForumContext.GetAbsoluteUrl(ForumUrls.NEW_POST), new jQueryAjaxOptions { Loading = true, Type = AjaxRequestDataType.Script }, new { @id = "_f" }))
    {

        <div>
            @Html.AntiForgeryToken()        
            @Html.Hidden("cmd", (string) ViewBag.Cmd)
            @Html.AntiModelInjection("cmd", (string) ViewBag.Cmd)
            <table>
                @if (ForumContext.AllowStickyPosts && (_isNewPost || (_cmd == CommandType.Edit && Model.ReplyTo == 0)))
                {
                    <tr>
                        <td class="table-cell">
                            @ForumContext.GetMvcText(LanguageSection.POST, "STICKY")
                        </td>
                        <td class="table-cell">
                            @*@Html.DropDownList("priority", (List<SelectListItem>)ViewBag.PriorityTypes, new { @class = "select" })*@
                            <div id="priority-type">
                                @Html.RadioButtonGroup("priority", (List<SelectItem>) ViewBag.PriorityTypes, Model != null ? Model.Priority : 0, new {@class = "radio-group-panel"})
                            </div>
                        </td>
                    </tr>

                    <tr id="_datetimeout" style="display: none">
                        <td class="table-cell">
                            @ForumContext.GetMvcText(LanguageSection.POST, "PRIORITY_DATEEXPIRE")
                        </td>
                        <td class="table-cell">
                            @Html.TextBox("date_expires", Model != null ? Model.PriorityExpires : DateTime.UtcNow.AddYears(1).ToUserTimeZoneDateTime(), new {@class = "input datepicker {datetimeFormat:'O/D/Y H:M a',minDatetime:new Date()} "})
                        </td>
                    </tr>
                }
                <tr>
                    <td class="table-cell w25">
                        @ForumContext.GetMvcText(LanguageSection.POST, _cmd == CommandType.NewPoll ? "Question" : "TOPIC_NAME")
                    </td>
                    <td class="table-cell">
                        @Html.TextBox("TopicName", _cmd == CommandType.Edit && Model != null ? Model.TopicName : string.Empty, new {@class = "input {validate:{required:@, maxlength:200}}".Replace("@", _isNewPost.ToString().ToLower())})
                        @*@Html.TextBoxFor(x => x.TopicName, new { @class = "input {validate:{required:@, maxlength:200}}".Replace("@", _required.ToString().ToLower()) })*@
                    </td>
                </tr>
                @if (_cmd == CommandType.NewPoll || (_cmd == CommandType.Edit && Model.IsPoll))
                {

                    <tr>
                        <td class="table-cell v-top">
                            @ForumContext.GetMvcText(LanguageSection.POST, "POLL_ANSWERS")
                        </td>
                        <td class="table-cell">
                            @Html.Partial("_PollAnswer", (List<PollAnswer>) ViewBag.PollAnswers)
                        </td>
                    </tr>


                    /* <tr>
                    <td class="table-cell v-top">
                        &nbsp;
                    </td>
                    <td class="table-cell">
                        @Html.CheckBox("MultipleChoice", Model != null && Model.MultipleChoice, ForumContext.GetText(LanguageSection.POST, "MULTIPLE_CHOICE"), null)
                    </td>
                </tr>
                
                
                 <tr>
                    <td class="table-cell v-top">
                        @ForumContext.GetMvcText(LanguageSection.POST, "Expires")
                    </td>
                    <td class="table-cell">
                        @Html.TextBox("poll_expires", Model != null ? Model.Expires : DateTime.UtcNow.AddYears(1).ToUserTimeZoneDateTime(), new { @class = "input datepicker {datetimeFormat:'O/D/Y H:M a',minDatetime:new Date()} " })
                    </td>
                </tr>
                */

                }
                @if (_isMod && ((Model != null && Model.ReplyTo == 0) || _cmd == CommandType.NewPost))
                {
                    <tr>
                        <td class="table-cell">
                            @ForumContext.GetMvcText(LanguageSection.POST, "REMOTE_URL")
                        </td>
                        <td class="table-cell">
                            @Html.TextBoxFor(x => x.RemoteUrl, new {@class = "input {validate:{maxlength:255}}"})
                        </td>
                    </tr>
                }
                <tr>
                    <td class="table-cell v-top">
                        @ForumContext.GetMvcText(LanguageSection.POST, "Message")
                    </td>
                    <td class="table-cell">
                        @*@Html.TextAreaFor(x => x.Message, new { @class = "tinymce input {tinymce:{mode:'medium'}}", @style = "width:99.5%;height:350px" })*@
                        @Html.Kaio().EditorFor(x => x.Message, new EditorOptions {ToolbarMode = EditorToolbarMode.Medium}, new {@style = "width:99.5%;height:350px"})
                    </td>
                </tr>
                <tr>
                    <td class="table-cell">
                        @ForumContext.GetMvcText(LanguageSection.POST, "TAGS")
                    </td>
                    <td class="table-cell">
                        @Html.TextBoxFor(x => Model.Tags, new {@class = "input {validate:{maxlength:136}}"})
                    </td>
                </tr>

                @if (_cmd == CommandType.Edit)
                {
                    <tr>
                        <td class="table-cell">
                            @ForumContext.GetMvcText(LanguageSection.POST, "REASON")
                        </td>
                        <td class="table-cell">
                            @Html.TextBoxFor(x => Model.Reason, new {@class = "input {validate:{required:1,maxlength:145}}"})
                        </td>
                    </tr>

                }

                <tr>
                    <td class="table-cell right" colspan="2">
                        @*<input type="submit" class="ui-button icon-16 go" value="@ViewBag.ButtonText" />*@
                        @Html.Link("javascript://", (string)ViewBag.ButtonText, new { @class = "ui-button large", @onclick = "$('#_f').submit()" })
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="caption">
                        @ForumContext.GetMvcText(LanguageSection.POST, "OPTIONS")
                    </td>
                </tr>
                <tr>
                    <td class="table-cell" colspan="2">
                        @if (_smiles != null)
                        {
                            <fieldset>
                                <legend>@ForumContext.GetMvcText(LanguageSection.POST, "MESSAGE_ICON")</legend>
                                <div class="radio-panel">
                                    <input type="radio" name="Icon" value="" id="icon_none" /><label for="icon_none">@ForumContext.GetText(LanguageSection.POST, "NO_ICON")</label>
                                    @foreach (var ico in _smiles)
                                    {
                                        var id = "icon_" + ico.Id;
                                        var selected = Model != null && ico.Icon == Model.Icon;

                                        <input type="radio" name="Icon" value="@ico.Icon" id="@id" @String.Format("{0}", selected ? "checked=\"checked\"" : "")/>
                                        <label for="@id"><img src="@string.Format("{0}{1}", ForumContext.Configuration.SmilePath, ico.Icon)"></label>
                                    }
                                </div>
                            </fieldset>
                        }
                        @if (ForumContext.IsSuperMod || ForumContext.UserInfo.Permissions.SubscribeToTopics)
                        {
                            <fieldset>
                                <legend>@ForumContext.GetMvcText(LanguageSection.SUBSCRIPTION, "PAGE_NAME")</legend>
                                <table>
                                    <tr>
                                        <td class="w20">
                                            @ForumContext.GetMvcText(LanguageSection.SUBSCRIPTION, "NOTIFICATION_TYPE")
                                        </td>
                                        <td>
                                            @Html.DropDownList("notify", (List<SelectListItem>) ViewBag.NotifyType, new {@class = "select"})
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        }
                        @if (_isMod || ForumContext.UserInfo.Permissions.MaxUploadStorage > 0)
                        {
                            <fieldset>
                                <legend>@ForumContext.GetMvcText(LanguageSection.ATTACHMENTS, "ATTACHMENT_FILE")</legend>
                                <table>
                                    <tr>
                                        <td class="w20 v-top">
                                            @ForumContext.GetMvcText(LanguageSection.ATTACHMENTS, "ATTACHMENT_MANAGEMENT")
                                        </td>
                                        <td>
                                            <div id="_fileChooice" class="file-chooice-panel">
                                            </div>
                                            <input type="button" onclick="$.FlexExplorer.open()" class="ui-button" value="@ForumContext.GetText(LanguageSection.ATTACHMENTS, "Add_File")"/>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        }
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="table-cell right">
                        @Html.Link("javascript://", (string) ViewBag.ButtonText, new {@class = "ui-button large", @onclick = "$('#_f').submit()"})
                    </td>
                </tr>
            </table>
        </div>
    }
</div>
@using (Html.BeginScriptBlock())
{
    
    <script type="text/javascript">
    
        function showDateTimeOut(val) {
            if (val > 0) {
                $('#_datetimeout').fadeIn();
            } else {
                $('#_datetimeout').hide();
            }
        };


        $(function () {

            $('#priority-type input').unbind('.mvcforum').bind('click.mvcforum', function () {

                showDateTimeOut($(this).val());

            });

            showDateTimeOut($('#priority-type input:checked').val());
        });
   
    </script>
}
